<?xml version = '1.0' encoding = 'UTF-8'?>
<HBRRepo><variables/><rulesets/><rules><rule id="1" name="OQP_Validate Adjustment By Dimension" product="Planning"><property name="application">SalesPln</property><property name="plantype">OEP_QTP</property><property name="seeded">true</property><script type="groovy">			/*PURPOSE: This rule ensures user can make adjustments by product or Accounts dimension with in given territory or resource.*/
                 String PrevEntityName;
                /*fetchs rows of the grid*/
            	List&lt;DataGrid.Row> rows = operation.grid.getRows();
				int TotRows= rows.size()                					   
				int iRow=0;
                Double AllocQuota = 0;					
				Double AdjVal = 0;                    
                Double AdjustQuota = 0;
                Double roundValue;
				if (TotRows>1)
				for (DataGrid.Row row : rows) 
				{                	
					List&lt;DataGrid.DataCell> subRows = row.getData();
					for(DataGrid.DataCell cell : subRows) 
					{  
                    /*Accumalates Allocated Target Quota, Adjustment values and Target Quota for each territory*/
                   	 String periodName=cell.getPeriodName();
                      if(periodName.equals("YearTotal"))
                      {
                      	
                       	String AcctName = cell.getAccountName();
                       	String EntityName =cell.getEntityName();
                        
                       	if (iRow==0)
                       	{
                        /*Sets Previous entity*/
                      		 PrevEntityName=EntityName;                        
                       	}                        
                        if (AcctName.equals("OQP_Allocated Target Quota"))
                        {
                         	 AllocQuota=AllocQuota+cell.getData();
						}		
                       if (AcctName.equals("OQP_Quota Adjustment Value"))
                        {
                         	 AdjVal=AdjVal+cell.getData()  ; 
                        }
                        if (AcctName.equals("OQP_Adjusted Target Quota"))
                        {
                        	AdjustQuota=AdjustQuota+cell.getData()  ;
                        }
                         if (PrevEntityName!=cell.getEntityName())
                         {
                           if (AdjustQuota>(AllocQuota+AdjVal))
                           {
                           	roundValue=(AdjustQuota-(AllocQuota+AdjVal))
                           }
                           if (AdjustQuota&lt;(AllocQuota+AdjVal))
                           {
                           	roundValue=((AllocQuota+AdjVal)-AdjustQuota)
                           }                           
                           if (AdjustQuota==(AllocQuota+AdjVal))
                           {
                           	roundValue=0;
                           }
                           
                         /*when new entity comes up, we ensuure that total of all custom accounts same or not*/
                         	if (roundValue&lt;2)                       	                               
                             {
                             	PrevEntityName=cell.getEntityName();
                                AllocQuota = 0;					
							    AdjVal = 0;                    
                    	        AdjustQuota = 0;
                             }
                             else
                             {
                             	 throwVetoException("The Adjustments changed the allocated quota. Ensure its equal to overall quota of "+ AdjustQuota.round() +" for Entity:"+PrevEntityName)  
                             }
                         }
                      }
				  }					
					iRow=iRow+1;
				}   
		  	
		
		</script></rule></rules><components/><deployobjects><deployobject product="2" application="salespln" plantype="oep_qtp" obj_id="1" obj_type="1" name="OQP_VALIDATE ADJUSTMENT BY DIMENSION"/></deployobjects></HBRRepo>